package github.flandre.examplemod.common.block;


import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.material.Material;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;

import javax.annotation.Nullable;

//带方向的方块
public class ExampleDirectionBlock extends Block {
    //方块方向
    private static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;

    public ExampleDirectionBlock() {
        super(Properties.create(Material.ROCK).hardnessAndResistance(1.5F,100.0F));
        //初始化方向
        this.setDefaultState(this.getStateContainer().getBaseState().with(FACING, Direction.NORTH));
    }
    //放置方块的朝向 玩家视角的反方向
    @Nullable
    @Override
    public BlockState getStateForPlacement(BlockItemUseContext context) {
        return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite());
    }

    //翻转和镜像
    @Override
    public BlockState rotate(BlockState state, Rotation rot) {
        return state.with(FACING, rot.rotate(state.get(FACING)));
    }

    @Override
    public BlockState mirror(BlockState state, Mirror mirrorIn) {
        return state.rotate(mirrorIn.toRotation(state.get(FACING)));
    }

    @Override
    protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
        builder.add(FACING);
    }

}
